/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package headquarters;

import com.vividsolutions.jts.geom.Point;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author marcin
 */
public class Main {

    @Resource(mappedName = "jms/ConnectionFactory")
    private static ConnectionFactory connectionFactory;
    @Resource(mappedName = "jms/Queue")
    private static Queue queue;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws JMSException {

        int numberCars = 50;
        Connection connection = connectionFactory.createConnection();
//        List<City> list = new City().findAll(); // lista obiektów klasy City (gid, nazwa ulicy, LineString)
        Hashtable<Integer, ArrayList<Point>> streetPoints = new Hashtable<Integer, ArrayList<Point>>();

        EntityManagerFactory emf;
        Random rand = new Random();

        emf = Persistence.createEntityManagerFactory("PZMDB-app-clientPU");

       
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int i = 0; i < numberCars; i++) {
            int number = rand.nextInt(5);
           
            
            try {
                exec.execute(new CarThread(connection, queue, emf, number));
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        exec.shutdown();
        } // main
    } // class
    


